{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 对偶形式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def calcGramMaxtrix(X):\n",
    "    m = X.shape[0]\n",
    "    gram = np.zeros((m, m))\n",
    "    for i in range(m):\n",
    "        for j in range(i, m):\n",
    "            gram[i, j] = X[i].dot(X[j])\n",
    "            gram[j, i] = X[i].dot(X[j])\n",
    "    return gram\n",
    "\n",
    "def calcI(X, y, a, b, i, gram):\n",
    "    #print (X.shape, y.shape, a. shape)\n",
    "    sum = 0\n",
    "    for j in range(X.shape[0]):\n",
    "        sum += a[j] *y[j] * gram[j, i]\n",
    "    return (sum + b)*y[i]\n",
    "        \n",
    "# 感知机原始形式\n",
    "def perceptron(X, y, eta):\n",
    "    a, b = np.zeros(X.shape[0]),0\n",
    "    gram = calcGramMaxtrix(X)\n",
    "    isFinished = False\n",
    "    while not isFinished:\n",
    "        isFinished = True\n",
    "        for i in range(X.shape[0]):\n",
    "            if calcI(X, y, a, b, i, gram) <= 0:\n",
    "                isFinished = False\n",
    "                a[i] += eta\n",
    "                b += eta * y[i]\n",
    "    def f(x):\n",
    "        sum = 0\n",
    "        for j in range(X.shape[0]):\n",
    "            sum += a[j] *y[j] * X[j].dot(x)\n",
    "        return sum + b\n",
    "    return a, b, f"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 把结果打印出来\n",
    "def plotModel(X, y, a, b, f):\n",
    "    for x in X:\n",
    "        if f(x) <= 0:\n",
    "            plt.scatter(x[0],x[1], color='red')\n",
    "        else:\n",
    "            plt.scatter(x[0],x[1], color='blue')\n",
    "    w = (a * y * X.T).T.sum(axis=0)\n",
    "    print (w.shape)\n",
    "    line_x0 = np.array([1, 5])\n",
    "    if w[1] == 0:\n",
    "        line_x0 = [-b/w[0], -b/w[0]]\n",
    "        line_x1 = [-1, 3]\n",
    "    else:\n",
    "        line_x1 = np.array((-b - w[0]*line_x0) / w[1])\n",
    "    #plt.scatter(X[index,0],X[index,1], s=150, c='none', alpha=0.7, linewidth=1.5, edgecolor='#AB3319')\n",
    "    plt.plot(line_x0, line_x1)\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2,)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAD4CAYAAADxeG0DAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAfvklEQVR4nO3deXRV9b3+8fcnEyGMQsKUEAIkwSqzERkDMtW2arXOolXQIlpG5Q69Xat33btWe3+1CFQsIIqKiorWtlprNcyDjAHFCckAYRCEMIUhZP7+/khsLQYh5Jzss5PntRaLc/bZ2ftZX8iTnb3P/h5zziEiIv4V5nUAERGpHRW5iIjPqchFRHxORS4i4nMqchERn4vwYqexsbEuKSnJi12LiPjW1q1bjzjn4s5d7kmRJyUlkZmZ6cWuRUR8y8z2VLdcp1ZERHxORS4i4nMqchERn1ORi4j4nIpcRMTnVOQiIj5X6yI3s2gz22xm283sMzP7n0AEE6lrixdDUhKEhVX+vXix14lCm8YrdATifeTFwHDn3GkziwTWmdnfnXMbA7BtkTqxeDGMHw+FhZXP9+ypfA4wZox3uUKVxiu01PqI3FU6XfU0suqPJjkXX/nlL/9ZSl8rLKxcLt+m8QotATlHbmbhZvYRcBhY6pzbVM06480s08wy8/PzA7FbkYDZu7dmyxs6jVdoCUiRO+fKnXO9gQSgn5l1r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/4xXmYWAbSgjk6rnS+Tc+6oc6646ukzwFV1EGcQcKOZ5QGvAcPN7OVz1vFirC6Yy6Pxwjl3oOrvw8CfgX7nrBLQ70U/F/nbwE+rrv72Bwqccwe9DmVm7b4+N2hm/agc46N1sF8DFgI7nHMzz7NanY/ZxeTyYszMLM7MWlY9bgyMBL44Z7W3gfuqHt8KrHBVV6q8ynTOedQbqbzmEFTOuV845xKcc0lUXshc4Zy755zV6nSsLjaXF+NlZk3MrNnXj4HRwLnvcgvo92KtPrMzmMzsVSrfzRBrZvuB/6by4g/OufnAu1Re+c0BCoGxIZLrVuBhMysDzgJ3Bvs/dJVBwL3AJ1XnWAH+C0j8RjYvxuxicnkxZu2BRWYWTuUPjtedc++Y2f8Cmc65t6n8AfSSmeVQeXR5ZwhkmmxmNwJlVZnuD3Km8/J4rC42lxfj1Rb4c9WxSQTwinPuPTObAMH5XtQt+iIiPufnUysiIoKKXETE91TkIiI+pyIXEfE5FbmIiM+pyEVEfE5FLiLic/8fTwvtuoGWfGsAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 书上的例子\n",
    "X = np.array([[3,3],[4,3],[1,1]])\n",
    "y = np.array([1,1,-1])\n",
    "w, b, f = perceptron(X, y, eta=1)\n",
    "plotModel(X, y, w, b, f)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "打一份线性可分的数据\n",
    "我选择了skearn.datasets的iris数据第1类和第2类的后面两个特征"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAs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aJtCPmXyS8a8lfTki/rTs/lSV7SnbP5F/v0DSHklfKbdX1RIRvx8R2yNiRtINkj4VEW8ouVuVZPvCfPGDbF8o6VpJI1shmEygt31Y0uclvcD2su2byu5TRV0l6Y3Knr6O5tt1ZXeqgi6W9GnbD0q6X9kYPcsH0avnSfqc7QckfVHSv0TER0fVeDLLKwEArSXzRA8AaI1ADwCJI9ADQOII9ACQOAI9ACSOQA8AiSPQA0Di/h9h0FQQVflsbgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn import datasets\n",
    "\n",
    "iris = datasets.load_iris()\n",
    "X = iris.data\n",
    "y = iris.target\n",
    "\n",
    "X = X[y<2,2:]\n",
    "y = y[y<2]\n",
    "plt.scatter(X[y==0,0],X[y==0,1], color='red')\n",
    "plt.scatter(X[y==1,0],X[y==1,1], color='blue')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n",
       "       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,  1,\n",
       "        1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,\n",
       "        1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,\n",
       "        1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y[y==0]=-1\n",
    "y"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "由于感知机要求的y的标签为-1和1，当前y的标签为0，1\n",
    "需要把标签0全部改成标签-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2,)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD8CAYAAAB0IB+mAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nO3dd3hU1fY38O/KJCEJXQglARJAeglIRGrQS0cFRVEUlevVGykKxIbt2n6Waw1gQaPoVUEUUQQpAWyEDqGELp2AtNB7QpL1/jHhFWIySaZkn5n5fp7nPDNz9plz1pxHFzt7r9kjqgoiIvJ9AaYDICKi0sGET0TkJ5jwiYj8BBM+EZGfYMInIvITTPhERH7C5YQvIrVF5DcR2SwiG0VkZAHHiIiME5HtIrJORK5x9bpERFQygW44RzaAx1R1tYiUB7BKROar6qbLjukNoEHedh2A8XmPRERUSlzu4avqAVVdnff8NIDNACLzHdYPwJdqtwxAJRGp6eq1iYio+NzRw///RCQaQGsAy/M1RQLYe9nrfXn7DuR7fzyAeAAoW7Zsm8aNG7szPCIin7dq1aojqhpeUJvbEr6IlAPwPYBRqnoqf3MBb/nbmg6qmgQgCQBiY2M1NTXVXeEREfkFEdlTWJtbqnREJAj2ZD9JVX8o4JB9AGpf9roWgP3uuDYRERWPO6p0BMAEAJtV9d1CDpsB4L68ap12AE6q6oFCjiUiIg9wx5BORwD3AlgvImvz9j0DoA4AqOpHAGYD6ANgO4BzAO53w3WJiKgEXE74qroIBY/RX36MAhju6rWIiMh5/KYtEZGfYMInIvITTPhERH7CJxP+b1sO4+vl6eDP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Cu6UAsTAHME5FVIhJvKggmfD8mIuUAfA9glKqeMh2PFalqjqq2AlALQFsR4TDhZUTkJgCHVXWV6VgsrqOqXgOgN4DheUPPpY4J30/ljUl/D2CSqv5gOh6rU9UTAH4H0MtwKFbTEUDfvDHqbwD8Q0Qmmg3JelR1f97jYQDTALQ1EQcTvh/Km4ycAGCzqr5rOh6rEpFwEamU9zwUQDcAW8xGZS2q+rSq1lLVaAADAfyqqvcYDstSRKRsXnEERKQsgB4AjFQR+lzCF5HJAJYCaCQi+0TkAdMxWVBHAPfC3htbm7f1MR2UBdUE8JuIrAOwEvYxfJYdUklVB7BIRNIArAAwS1WTTQTic2WZRERUMJ/r4RMRUcGY8ImI/AQTPhGRn2DCJyLyE0z4RER+ggmfiMhPMOETEfmJ/wd0iSqHLIPgRQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# iris数据\n",
    "w, b, f = perceptron(X, y, eta=0.01)\n",
    "plotModel(X, y, w, b, f)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
